package com.tao.vo;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.tao.entity.Message;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author  诸葛先生
 * 功能：返回一个统一的数据
 */
@Data
public class SocketResult {

    /**
     * 消息是谁发给你的
     */
    private String name;
    /**
     * 什么时候发送的
     */
    private LocalDateTime time;
    /**
     * 内容
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String message;
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @JsonInclude(JsonInclude.Include.NON_NULL)
//    private Message messageObj;


    // 定义格式标准


    public static TextWebSocketFrame fail(String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new SocketResult("系统消息",LocalDateTime.now(),message)));

    }

    public static TextWebSocketFrame success(String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new SocketResult("系统消息",LocalDateTime.now(),message)));
    }
//    public static TextWebSocketFrame success(Message message) {
//        return new TextWebSocketFrame(JSON.toJSONString(new SocketResult("系统消息",LocalDateTime.now(),message)));
//    }

    public static TextWebSocketFrame success(String username,String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new SocketResult(username,LocalDateTime.now(),message)));
    }

    public SocketResult() {
    }

    public SocketResult(String name, LocalDateTime time, String message) {
        this.name = name;
        this.time = time;
        this.message = message;
    }
//    public SocketResult(String name, LocalDateTime time, Message message) {
//        this.name = name;
//        this.time = time;
//        this.messageObj = message;
//    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public LocalDateTime getTime() {
        return time;
    }

    public void setTime(LocalDateTime time) {
        this.time = time;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "{\"name\":\"" + name + "\", \"time\":\"" + time + "\", \"message\":\"" + message + " }";
    }
}
